package simple

import "fmt"

type Message string
type Channel struct {
	Message Message
}

func (c Channel) GetMsg() Message {
	return c.Message
}

type BroadCast struct {
	Channel Channel
}

func (b BroadCast) Start() {
	msg := b.Channel.GetMsg()
	fmt.Println(msg)
}

// 三者的 init 方法：

func NewMessage() Message {
	return Message("Hello Wire!")
}
func NewChannel(m Message) Channel {
	return Channel{Message: m}
}
func NewBroadCast(c Channel) BroadCast {
	return BroadCast{Channel: c}
}

// OldStart 传统方式
func OldStart() {
	message := NewMessage()
	channel := NewChannel(message)
	broadCast := NewBroadCast(channel)

	broadCast.Start()
}

func WireStart() {
	// 调用生成的代码
	b := InitializeBroadCast()
	b.Start()
}
